﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace CNKI.Graduate.Framework.Cache
{
    class JsonHelper
    {
        public static T ToObject<T>(string json)
        {
            JsonSerializerSettings setting = new JsonSerializerSettings();
            setting.NullValueHandling = NullValueHandling.Ignore;
            setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
            return JsonConvert.DeserializeObject<T>(json, setting);
        }

        public static string ToJson<T>(T obj)
        {
            JsonSerializerSettings setting = new JsonSerializerSettings();
            setting.NullValueHandling = NullValueHandling.Ignore;
            setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
            return JsonConvert.SerializeObject(obj, setting);
        }
    }
}
